<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title><c:if test="${plan.planid != null}">编辑</c:if><c:if test="${plan.planid == null}">添加</c:if>饮食计划</title>
    <style>
        /* 全局配色定义 - 绿色系和谐版 */
        :root {
            --primary-green: #4CAF50;       /* 主绿色 - 鲜绿 */
            --secondary-green: #388E3C;     /* 次绿色 - 深绿 */
            --tertiary-green: #81C784;      /* 三级绿 - 中绿 */
            --quaternary-green: #A5D6A7;    /* 四级绿 - 浅绿 */
            --light-green-bg: #E8F5E9;      /* 浅绿色背景 */
            --white: #fff;                  /* 白色 */
            --text-color: #333;             /* 主文本色 */
            --light-text: #555;             /* 次文本色 */
            --border-color: #D1E8D4;        /* 绿色边框 */
            --shadow-color: rgba(76, 175, 80, 0.08); /* 绿色系阴影 */
            --transition: all 0.3s ease;    /* 过渡效果 */
        }

        /* 基础样式 */
        body {
            font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
            background-color: var(--light-green-bg);
            color: var(--text-color);
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 900px;
            margin: 30px auto;
            padding: 35px;
            background: var(--white);
            border-radius: 12px;
            box-shadow: 0 8px 24px var(--shadow-color);
        }

        /* 标题样式 */
        h2 {
            color: var(--secondary-green);
            margin-bottom: 28px;
            padding-bottom: 12px;
            border-bottom: 2px solid var(--quaternary-green);
            font-weight: 600;
            font-size: 1.8rem;
        }

        /* 表单组样式 */
        .form-group {
            margin-bottom: 28px;
            position: relative;
        }

        label {
            display: block;
            margin-bottom: 10px;
            font-weight: 500;
            color: var(--text-color);
            font-size: 1.05rem;
        }

        .required-field::after {
            content: " *";
            color: #F44336;
            margin-left: 3px;
        }

        /* 输入框样式 */
        input[type="text"],
        input[type="date"],
        input[type="number"],
        select {
            width: 100%;
            padding: 14px 18px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            box-sizing: border-box;
            font-size: 1rem;
            transition: var(--transition);
        }

        input[type="text"]:focus,
        input[type="date"]:focus,
        input[type="number"]:focus,
        select:focus {
            outline: none;
            border-color: var(--tertiary-green);
            box-shadow: 0 0 0 4px rgba(129, 199, 132, 0.2);
        }

        /* 按钮样式 - 绿色系和谐版 */
        .btn {
            padding: 12px 30px;
            background-color: var(--primary-green);
            color: var(--white);
            border: none;
            border-radius: 8px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-weight: 500;
            font-size: 1rem;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 12px rgba(76, 175, 80, 0.15);
        }

        .btn:hover {
            background-color: var(--secondary-green);
            transform: translateY(-3px);
            box-shadow: 0 6px 16px rgba(76, 175, 80, 0.25);
        }

        .btn-cancel {
            background-color: #E57373;        /* 浅红色 - 与绿色形成对比 */
            margin-left: 15px;
            box-shadow: 0 4px 12px rgba(229, 115, 115, 0.2);
        }

        .btn-cancel:hover {
            background-color: #EF5350;
        }

        /* 错误提示样式 */
        .error {
            color: #F44336;
            font-size: 0.9rem;
            margin-top: 6px;
            display: block;
            line-height: 1.3;
        }

        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 35px 0 0;
            background: var(--white);
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 16px var(--shadow-color);
        }

        th, td {
            padding: 18px 20px;
            text-align: left;
            border-bottom: 1px solid var(--quaternary-green);
            font-size: 0.95rem;
        }

        th {
            background-color: var(--light-green-bg);
            color: var(--secondary-green);
            font-weight: 600;
            font-size: 1rem;
        }

        tr:hover {
            background-color: #F0F9F1;
        }

        .table-title {
            font-size: 1.2rem;
            font-weight: 600;
            color: var(--secondary-green);
            margin: 0 0 18px;
            display: flex;
            align-items: center;
        }

        .table-title::before {
            content: "";
            display: inline-block;
            width: 12px;
            height: 12px;
            background-color: var(--primary-green);
            border-radius: 3px;
            margin-right: 10px;
        }

        .actions {
            text-align: center;
        }

        /* 操作按钮微调 */
        .actions .btn {
            padding: 8px 16px;
            font-size: 0.9rem;
            box-shadow: none;
        }

        .actions .btn:first-child {
            margin-right: 8px;
        }

        /* 编辑/删除按钮颜色调整 */
        .actions .btn {
            background-color: var(--tertiary-green);
        }

        .actions .btn:hover {
            background-color: #66BB6A;
        }

        .actions .btn-delete {
            background-color: #E57373;
        }

        .actions .btn-delete:hover {
            background-color: #EF5350;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>
        <c:if test="${plan.planid != null}">编辑</c:if>
        <c:if test="${plan.planid == null}">添加</c:if>
        饮食计划
    </h2>

    <form action="${pageContext.request.contextPath}${plan.planid != null ? '/plan/edit' : '/plan/add'}" method="post">
        <input type="hidden" name="planid" value="${plan.planid}">

        <div class="form-group">
            <label for="planname" class="required-field">计划名称:</label>
            <input type="text" id="planname" name="planname" required placeholder="请输入计划名称" value="${plan.planname}">
            <span class="error">${errors.planname}</span>
        </div>

        <div class="form-group">
            <label for="userid" class="required-field">用户ID:</label>
            <input type="number" id="userid" name="userid" required placeholder="请输入用户ID" value="${plan.userid}">
            <span class="error">${errors.userid}</span>
        </div>

        <div class="form-group">
            <label for="stardate" class="required-field">开始日期:</label>
            <input type="date" id="stardate" name="stardate" required value="${plan.stardate}">
            <span class="error">${errors.stardate}</span>
        </div>

        <div class="form-group">
            <label for="enddate" class="required-field">结束日期:</label>
            <input type="date" id="enddate" name="enddate" required value="${plan.enddate}">
            <span class="error">${errors.enddate}</span>
        </div>

        <button type="submit" class="btn">
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16" style="margin-right: 6px;">
                <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/>
            </svg>
            保存
        </button>
        <a href="${pageContext.request.contextPath}/plan/list" class="btn btn-cancel">
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x" viewBox="0 0 16 16" style="margin-right: 6px;">
                <path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"/>
            </svg>
            取消
        </a>
    </form>

    <!-- 绿色系表格示例 -->
    <div class="table-container">
        <div class="table-title">饮食计划列表</div>
        <table>
            <thead>
            <tr>
                <th>ID</th>
                <th>计划名称</th>
                <th>用户ID</th>
                <th>开始日期</th>
                <th>结束日期</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${plans}" var="plan">
                <tr>
                    <td>${plan.planid}</td>
                    <td>${plan.planname}</td>
                    <td>${plan.userid}</td>
                    <td>${plan.stardate}</td>
                    <td>${plan.enddate}</td>
                    <td class="actions">
                        <a href="${pageContext.request.contextPath}/plan/edit/${plan.planid}" class="btn" style="background-color: var(--tertiary-green); color: white;">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="white" class="bi bi-pencil" viewBox="0 0 16 16" style="margin-right: 4px;">
                                <path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 7.586 3 15l1.586 1.586 4.086-4.086L14.414 3z"/>
                            </svg>
                            编辑
                        </a>
                        <a href="${pageContext.request.contextPath}/plan/delete/${plan.planid}" class="btn" style="background-color: #f44336; color: white;" onclick="return confirm('确定要删除此计划吗?')">
                            <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="white" class="bi bi-trash" viewBox="0 0 16 16" style="margin-right: 4px;">
                                <path d="M5.5 5.5A.5.5 0 0 1 6 5h4a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5H6a.5.5 0 0 1-.5-.5v-1zm2.5 0a.5.5 0 0 0-1 0v1a.5.5 0 0 0 1 0v-1zm3 .5a.5.5 0 0 0-1 0v1a.5.5 0 0 0 1 0v-1zm-7 10a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2v-1a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v1zm0 1a1 1 0 0 1-1-1v-1a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H7zm4-9.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1z"/>
                            </svg>
                            删除
                        </a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>